using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using DAL;
using BUS;
using Utility;

public partial class Admin_SanPham_Add : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        //try
        //{
            int id = int.Parse(Request.QueryString["id"]);
            // Get the HttpFileCollection
            HttpFileCollection hfc = Request.Files;
            for (int i = 0; i < hfc.Count; i++)
            {
                HttpPostedFile hpf = hfc[i];
                if (hpf.ContentLength > 0)
                {                    
                    hpf.SaveAs(Server.MapPath("~/Photos") + "\\" +
                    System.IO.Path.GetFileName(hpf.FileName));

                    System .Drawing .Image img = System .Drawing .Image .FromFile (Server .MapPath ("~/Photos/"+ hpf .FileName) );
                    ImageUtility .MakeThumbnailPhoto (img ,100,100, Server .MapPath ("~/Photos/Thumb/"),hpf .FileName );

                    tbHinhAnh ha = new tbHinhAnh();
                    ha.masp = id;
                    ha.hinhminhhoa = hpf.FileName.ToString();
                    tbHinhAnhBUS.Insert(ha);
                    Response.Write("<b>File: </b>" + hpf.FileName + "  <b>Size:</b> " +
                        hpf.ContentLength + "  <b>Type:</b> " + hpf.ContentType + " Uploaded Successfully <br/>");
                   
                                   
                }
                
            }
            Response.Redirect("SanPham_List.aspx");
    }
}

